package myJs.implicits

import myJs.myPkg.jquery._
import myJs.myPkg.Implicits._
import org.scalajs.dom.Element

import scala.scalajs.js
import myJs.implicits.Implicits._
import scalatags.Text.all.s

/**
 * Created by Administrator on 2020/1/16
 */
trait MyJqueryTool {

  implicit class MyJquery(jq: JQuery) {

    def myVal = {
      if (jq.`val`() == null) {
        ""
      } else jq.`val`().toString
    }

    def select2Val = {
      jq.select2("data").asInstanceOf[js.Array[JDJAn]].map { dict =>
        dict("id").toString
      }
    }

    def select2Val(vs: js.Array[String]) = {
      jq.`val`(vs).select2()
    }

    def size = {
      jq.mapElems(y => y).size
    }

    def isChecked = {
      jq.prop("checked").get.toString.toBoolean
    }

    def isVisible = {
      jq.is(":visible")
    }

    def isHidden = {
      jq.is(":hidden")
    }

    def findInputByName(name: String) = {
      jq.find(s":input[name='${name}']")
    }

  }

}
